<template>
	<view class="px-10 pt-10  pb-100">
		<uImage v-model="form.face_url" title="换脸主图"></uImage>
		<uImage v-model="form.template_url" title="换脸模板图"></uImage>

		<y-footer @success="submit" mode>{{sbumitText}}</y-footer>
	</view>
</template>

<script setup>
	import { ref, computed } from 'vue';
	import { onLoad } from '@dcloudio/uni-app'
	import uImage from './modules/uImage.vue';
	import { getAppDetail, util } from '@/api/app.js'
import { $page, $tool } from '@/utils';
	const form = ref({
		app_id: 0,
		face_url: '',
		template_url: ''
	})
	const detail = ref({
		points: 0
	})
	const sbumitText = computed(() => {
		if (detail.value.points == 0) {
			return '免费生成'
		}
		return '消耗算力:' + detail.value.points
	})
	onLoad((option) => {
		if (option.id) {
			get({ id: option.id })
		} else {
			get({ type: 'facialFusion' })
		}
	})
	const get = (query) => {
		getAppDetail(query).then(res => {
			detail.value = res.data
			form.value.app_id = detail.value.id
		})
	}

	const submit = () => {
		if (!detail.value.id) {
			$tool.toast('应用不存在');
			return;
		}
		uni.showLoading({
			title: '生成中..'
		})
		form.value.app_id = detail.value.id
		util(form.value).then(res => {
			$tool.toast('生成成功');
			$page.open('/pages/app/result?type=facialFusion')
		})
	}
</script>

<style>

</style>